#include "stm32f10x.h"
#include "led.h"
#include "usart.h"
#include "stdio.h"

void delay(uint16_t time)
{
	uint16_t i =0;
	while(time--){
		i=12000;
		while(i--);
	}
}

int main()
{
	Led_init();
	usart_init();
	
	//³õÊ¼»¯Òý½Å
	GPIO_SetBits(GPIOA, GPIO_Pin_3);
	GPIO_SetBits(GPIOC, GPIO_Pin_13);

}

void EXTI1_IRQHandler(void)
{
	if (EXTI_GetITStatus( EXTI_Line1 ) != RESET){// ÅÐ¶ÏÊÇ·ñ·¢ÉúÖÐ¶Ï
		GPIO_ResetBits(GPIOA, GPIO_Pin_3);
		usartSendStr(USART1,"Open light success\r\n");
		delay(1000);
		GPIO_SetBits(GPIOA, GPIO_Pin_3);
		usartSendStr(USART1,"Close light success\r\n");
	}

	EXTI_ClearFlag(EXTI_Line1);
	
}

void USART1_IRQHandler(void)
{
	char temp;
	
	if(USART_GetITStatus(USART1,USART_IT_RXNE) != RESET){
		
		temp = USART_ReceiveData(USART1);

		if(temp == 'Y'){
			GPIO_ResetBits(GPIOC, GPIO_Pin_13);
			usartSendStr(USART1,"Open LED light success\r\n");
		}
		
		if(temp == 'N'){
			GPIO_SetBits(GPIOC, GPIO_Pin_13);
			usartSendStr(USART1,"Close LED light success\r\n");
		}
	}
}
	




#include "stm32f10x.h"                  // Device header
#include "usart.h"

void delay(uint16_t time)
{
	uint16_t i =0;
	while(time--){
		i=12000;
		while(i--);
	}
}

int main()
{
	usart_init();
	
	while(1)
	{
		usartSendStr(USART1,"Hello word\r\n");
		delay(1000);
	}

}



//点亮LED
/*void Delay_us(uint32_t xus)
{
	SysTick->LOAD = 72 * xus;				//????????
	SysTick->VAL = 0x00;					//???????
	SysTick->CTRL = 0x00000005;				//??????HCLK,?????
	while(!(SysTick->CTRL & 0x00010000));	//?????0
	SysTick->CTRL = 0x00000004;				//?????
}
 

void Delay_ms(uint32_t xms)
{
	while(xms--)
	{
		Delay_us(1000);
	}
}
 

void Delay_s(uint32_t xs)
{
	while(xs--)
	{
		Delay_ms(1000);
	}
} 



int main(void)
{
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);	 //使能PC端口时钟
 
//总分总形式
 GPIO_InitTypeDef  GPIO_InitStructure;//结构体开头
//三个固定成分
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;				 //PC12端口配置
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 		 //推挽输出
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;		 //IO口速度为50MHz

	//结尾
 GPIO_Init(GPIOA, &GPIO_InitStructure);					 //根据设定参数初始化GPIOC.12
	
	while(1)
	{
//以下可以自己定义
	//GPIO_SetBits(GPIOA,GPIO_Pin_12);
  //  Delay_s(1);
	GPIO_ResetBits(GPIOA,GPIO_Pin_12);
	//Delay_s(1);	//延时300ms
	}
}
*/



